package com.lanxin.oa.zc.controller;

import com.lanxin.util.TimeConverter;
import com.lanxin.bean.JcBasicdatavalue;
import com.lanxin.bean.ZcAsset;
import com.lanxin.bean.ZcAssettype;
import com.lanxin.bean.ZzEmployee;
import com.lanxin.oa.zc.service.ZcAssetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("zcset")
public class ZcAssetController extends TimeConverter {
    @Autowired
    private ZcAssetService zcservice;

    @RequestMapping("select")
    public ModelAndView selectzcaset(HttpServletRequest request) {
        List<ZcAsset> list = zcservice.selectzcAsset();
        List<ZcAssettype> zctype = zcservice.selectzcTypeIdandName();
        List<JcBasicdatavalue> jcbase=zcservice.selectJcbaseByIdandName();
        List<JcBasicdatavalue> jcbasedd=zcservice.selectJcbaseByDd();
        List<ZzEmployee> emp=zcservice.selectEmpByIdandName();
        ModelAndView mo=new ModelAndView();
        mo.addObject("zctype",zctype);
        mo.addObject("list",list);
        mo.addObject("jcbase",jcbase);
        mo.addObject("jcbasedd",jcbasedd);
        mo.addObject("emp",emp);
        mo.setViewName("../view/zc/zclist.jsp");
        return mo;
    }
    @RequestMapping("selecttj")
    public ModelAndView selectzcasettj(Integer type, String assetCode, String assetNanme) {
        List<ZcAsset> list = zcservice.selecttiaojian(type,assetCode,assetNanme);
        List<ZcAssettype> zctype = zcservice.selectzcTypeIdandName();
        List<JcBasicdatavalue> jcbase=zcservice.selectJcbaseByIdandName();
        List<JcBasicdatavalue> jcbasedd=zcservice.selectJcbaseByDd();
        List<ZzEmployee> emp=zcservice.selectEmpByIdandName();
        ModelAndView mo=new ModelAndView();
        mo.addObject("zctype",zctype);
        mo.addObject("list",list);
        mo.addObject("jcbase",jcbase);
        mo.addObject("jcbasedd",jcbasedd);
        mo.addObject("type",type);
        mo.addObject("assetCode",assetCode);
        mo.addObject("assetNanme",assetNanme);
        mo.setViewName("../view/zc/zclist.jsp");
        return mo;
    }
    @RequestMapping("insert")
    public ModelAndView insertzctype(HttpServletRequest request,ZcAsset zcAsset) {
        zcservice.insert(zcAsset);
        ModelAndView mo=new ModelAndView();
        mo.setViewName("redirect:select");
        return mo;
    }

    @RequestMapping("toupdate")
    public ModelAndView toupdatezctype(HttpServletRequest request,Integer oid) {
        ZcAsset zcaset=zcservice.selectzcAssetById(oid);
        List<ZcAssettype> zctype = zcservice.selectzcTypeIdandName();
        List<JcBasicdatavalue> jcbase=zcservice.selectJcbaseByIdandName();
        List<JcBasicdatavalue> jcbasedd=zcservice.selectJcbaseByDd();
        List<ZzEmployee> emp=zcservice.selectEmpByIdandName();
        ModelAndView mo=new ModelAndView();
        mo.addObject("zctype",zctype);
        mo.addObject("jcbase",jcbase);
        mo.addObject("jcbasedd",jcbasedd);
        mo.addObject("emp",emp);
        mo.addObject("zcaset",zcaset);
        mo.setViewName("../view/zc/zcupdate.jsp");
        return mo;
    }

    @RequestMapping("update")
    public ModelAndView updatezctype(ZcAsset zcAsset) {
        zcservice.updatezcAsset(zcAsset);
        ModelAndView mo=new ModelAndView();
        mo.setViewName("redirect:select");
        return mo;
    }

    @RequestMapping("baofei")
    public ModelAndView baofeizctype(Integer oid,String status) {
        zcservice.baofeizcAsset(oid,status);
        ModelAndView mo=new ModelAndView();
        mo.setViewName("redirect:select");
        return mo;
    }

    @RequestMapping("delete")
    public ModelAndView deletezctype(Integer oid) {
        zcservice.deletebaofeizcAset(oid);
        ModelAndView mo=new ModelAndView();
        mo.setViewName("redirect:select");
        return mo;
    }
}
